//DevNETCoder
//CopyRight By DevNET Group
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using STT.Entities;
using STT.DataAccess;
 
namespace STT.Business
{
    public class BTbMonHoc
    {
//-----------------------------------------------------------//
        public static DataTable SelectAll()
        {
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbMonHoc_SelectAll", null);
            return all;
        }
        public static DataTable SelectTop(int Top)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"Top", Top);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbMonHoc_SelectTop", pr);
            return all;
        }
//-----------------------------------------------------------//
        public static void Insert(ETbMonHoc OTbMonHoc)
        {
            SqlParameter[] pr = new SqlParameter[3];
            pr[0] = new SqlParameter(@"TenMonHoc", OTbMonHoc.TenMonHoc);
            pr[1] = new SqlParameter(@"SoHocTrinh", OTbMonHoc.SoHocTrinh);
            pr[2] = new SqlParameter(@"MaNganh", OTbMonHoc.MaNganh);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure,"TbMonHoc_Insert", pr);
        }
//-----------------------------------------------------------//
        public static void Update(ETbMonHoc OTbMonHoc)
        {
            SqlParameter[] pr = new SqlParameter[4];
            pr[0] = new SqlParameter(@"MaMonHoc", OTbMonHoc.MaMonHoc);
            pr[1] = new SqlParameter(@"TenMonHoc", OTbMonHoc.TenMonHoc);
            pr[2] = new SqlParameter(@"SoHocTrinh", OTbMonHoc.SoHocTrinh);
            pr[3] = new SqlParameter(@"MaNganh", OTbMonHoc.MaNganh);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure,"TbMonHoc_Update", pr);
        }
//-----------------------------------------------------------//
        public static void Delete(int MaMonHoc)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaMonHoc",MaMonHoc);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbMonHoc_Delete", pr);
        }
//-----------------------------------------------------------//
        public static ETbMonHoc SelectByID(int MaMonHoc)
        {
            ETbMonHoc OTbMonHoc = new ETbMonHoc();
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaMonHoc",MaMonHoc);
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure,"TbMonHoc_SelectByID", pr);
            if (idr.Read())
              OTbMonHoc = GetOneTbMonHoc(idr);
            idr.Close();
            idr.Dispose();
            return OTbMonHoc;
        }
//-----------------------------------------------------------//
        private static ETbMonHoc GetOneTbMonHoc(IDataReader idr)
       {
            ETbMonHoc OTbMonHoc = new ETbMonHoc();
                if (idr["MaMonHoc"] != DBNull.Value)
                    OTbMonHoc.MaMonHoc = (int)idr["MaMonHoc"];
                if (idr["TenMonHoc"] != DBNull.Value)
                    OTbMonHoc.TenMonHoc = (string)idr["TenMonHoc"];
                if (idr["SoHocTrinh"] != DBNull.Value)
                    OTbMonHoc.SoHocTrinh = (int)idr["SoHocTrinh"];
                if (idr["MaNganh"] != DBNull.Value)
                    OTbMonHoc.MaNganh = (int)idr["MaNganh"];
            return OTbMonHoc;
       }
//-----------------------------------------------------------//
        public static bool TestByID(int MaMonHoc)
        {
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"MaMonHoc",MaMonHoc);
            pr[1] = new SqlParameter(@"TestID",SqlDbType.Bit);
            pr[1].Direction = ParameterDirection.Output;
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure,"TbMonHoc_TestByID", pr);
            return Convert.ToBoolean(pr[1].Value);
        }
//-----------------------------------------------------------//
        public static List<ETbMonHoc> ListAll()
        {
            List<ETbMonHoc> list = new List<ETbMonHoc>();
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure, "TbMonHoc_SelectAll", null);
            while (idr.Read())
              list.Add(GetOneTbMonHoc(idr));
            if (idr.IsClosed == false)
            {
               idr.Close();
               idr.Dispose();
            }
            return list;
        }

        public static List<ETbMonHoc> ListTop(int Top)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"Top", Top);
            List<ETbMonHoc> list = new List<ETbMonHoc>();
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure, "TbMonHoc_SelectAll", pr);
            while (idr.Read())
              list.Add(GetOneTbMonHoc(idr));
            if (idr.IsClosed == false)
            {
               idr.Close();
               idr.Dispose();
            }
            return list;
        }
    }
 
}